// components/address/address.js
import event from '../../common/js/event.js'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: String,
    mechanism: String,
    city: String,
    name: String,
    mobile: String,
    right: Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {
    checked: false
  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
      event.on('toggle', this, function (self) {
        if (this !== self) {
          this.setData({
            checked: false
          })
        }
      })
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
      event.remove('toggle', this) 
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 设置默认选中状态
     */
    setDefault () {
      this.setData({
        checked: true
      })
    },
    bindtapchecked() {
      if (this.data.checked) {
        return
      }
      let checked = true
      this.setData({
        checked: checked
      })
      event.emit('toggle', this)
      this.triggerEvent('toggle', {})
    }
  }
})